package com.welink.cmp.adapter.api.metadata;

import com.welink.cmp.dto.metadata.datacenter.*;
import com.welink.cmp.meatdata.service.DataCenterAppService;
import com.welink.common.dto.PageResponse;
import com.welink.common.dto.SingleResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Data Center Service API
 * 提供机房的CRUD操作接口
 */
@RestController
@RequestMapping("/api/datacenter")
public class DataCenterServiceApi {

    @Autowired
    private DataCenterAppService dataCenterAppService;

    /**
     * 添加机房
     *
     * @param addCmd 添加机房的命令对象
     * @return 新增机房的ID
     */
    @PostMapping("/add")
    public SingleResponse<Long> addDataCenter(@RequestBody DatacenterAddCmd addCmd) {
        return SingleResponse.of(dataCenterAppService.addDataCenter(addCmd));
    }

    /**
     * 更新机房
     *
     * @param updCmd 更新机房的命令对象
     * @return 更新是否成功
     */
    @PostMapping("/update")
    public SingleResponse<Boolean> updateDataCenter(@RequestBody DatacenterUpdCmd updCmd) {
        return SingleResponse.of(dataCenterAppService.updateDataCenter(updCmd));
    }

    /**
     * 根据ID获取机房
     *
     * @param id 机房ID
     * @return 机房业务对象
     */
    @GetMapping("/get/{id}")
    public SingleResponse<DataCenterCO> getDataCenterById(@PathVariable Long id) {
        return SingleResponse.of(dataCenterAppService.getDataCenterById(id));
    }

    /**
     * 分页查询机房
     *
     * @param pageQry 分页查询条件
     * @return 分页响应，包括机房列表和分页信息
     */
    @PostMapping("/page")
    public PageResponse<DataCenterCO> pageQueryDataCenter(@RequestBody DatacenterPageQry pageQry) {
        return dataCenterAppService.dataCenterPageQuery(pageQry);
    }
}